import { request } from '@/sheep/request';
import { isEmpty } from 'lodash';
import { CRUD } from '@/sheep/request/crud';

export default {
  admin: {
    user: {
      // 获取登录、绑定二维码
      getQrcode: (params) =>
        request({
          url: 'wechat/admin/user/getQrcode',
          method: 'GET',
          params,
          options: {
            showErrorMessage: false,
          },
        }),
      // 检查扫码结果
      checkScan: (params) =>
        request({
          url: 'wechat/admin/user/checkScan',
          method: 'GET',
          params,
          options: {
            showErrorMessage: false,
          },
        }),
    },
    // 菜单管理
    menu: {
      ...CRUD('wechat/admin/menu'),
      copy: (data) =>
        request({
          url: 'wechat/admin/menu/copy/' + data,
          method: 'POST',
        }),
      publish: (data) =>
        request({
          url: 'wechat/admin/menu/publish/' + data,
          method: 'POST',
        }),
    },
    // 自动回复
    reply: {
      ...CRUD('wechat/admin/reply'),
    },
    // 素材管理
    material: {
      ...CRUD('wechat/admin/material'),
      // 选择素材
      select: (params) =>
        request({
          url: 'wechat/admin/material/select',
          method: 'GET',
          params,
        }),
    },
    // 微信配置
    config: {
      // 公众号配置
      officialAccount: (data) =>
        request({
          url: 'wechat/admin/config/officialAccount',
          method: isEmpty(data) ? 'GET' : 'PUT',
          data,
          options: {
            showSuccessMessage: !isEmpty(data),
          },
        }),
      // 小程序配置
      miniProgram: (data) =>
        request({
          url: 'wechat/admin/config/miniProgram',
          method: isEmpty(data) ? 'GET' : 'PUT',
          data,
          options: {
            showSuccessMessage: !isEmpty(data),
          },
        }),
      // 开放平台配置
      openPlatform: (data) =>
        request({
          url: 'wechat/admin/config/openPlatform',
          method: isEmpty(data) ? 'GET' : 'PUT',
          data,
          options: {
            showSuccessMessage: !isEmpty(data),
          },
        }),
    },
  },
};
